package com.work.yshop.model;

import java.util.Date;

/**
 * 聊天消息模型类
 */
public class ChatMessage {
    public static final int TYPE_SENT = 1;  // 发送的消息
    public static final int TYPE_RECEIVED = 2;  // 接收的消息
    
    private int id;
    private int contactId;  // 联系人ID
    private String content;  // 消息内容
    private long timestamp;  // 时间戳
    private int type;  // 消息类型：1-发送，2-接收
    private boolean isRead;  // 是否已读
    
    public ChatMessage() {
    }
    
    public ChatMessage(int contactId, String content, int type) {
        this.contactId = contactId;
        this.content = content;
        this.timestamp = new Date().getTime();
        this.type = type;
        this.isRead = type == TYPE_SENT; // 发送的消息默认已读
    }
    
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public int getContactId() {
        return contactId;
    }
    
    public void setContactId(int contactId) {
        this.contactId = contactId;
    }
    
    public String getContent() {
        return content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
    
    public int getType() {
        return type;
    }
    
    public void setType(int type) {
        this.type = type;
    }
    
    public boolean isRead() {
        return isRead;
    }
    
    public void setRead(boolean read) {
        isRead = read;
    }
    
    /**
     * 格式化时间
     */
    public String getFormattedTime() {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm", java.util.Locale.getDefault());
        return sdf.format(new Date(timestamp));
    }
} 